/**
 * Created by Jan-Home on 2016/11/15 0015.
 */

const keUrl = require('../src');

console.log(keUrl.decode('aa+bb+cc'));
console.log(keUrl.decode('aa%20bb%20cc'));

keUrl.setDebug(keUrl.DebugError);

console.log('is debug', keUrl.isDebug());
console.log('is debug error', keUrl.isDebug(keUrl.DebugError));
console.log('is debug log', keUrl.isDebug(keUrl.DebugLog));

let url = new keUrl('http://localhost/test2?a[a][a]=1&a[a][b]=2#ok');
let clone = url.clone({protocol: 'https', hash: ''}).replaceQuery('b[b][b]=bbb&b[b][你好]=333');

let query = keUrl.parseQuery('hello=world', { a: 1234 });
console.log(query);

let parse = keUrl.parseUrl(url);

let data = [
	'http://www.163.com/?hello=world',
	'http://www.baidu.com/s?wd=%B2%E2%CA%D4%BA%BA%D7%D6&rsv_bp=0&rsv_spt=3&inputT=7477',
	'https://www.google.com.hk/search?q=decodeURIComponent+URIError%3A+URI+malformed&oq=decodeURIComponent+URIError%3A+URI+malformed&aqs=chrome..69i57.972j0j7&sourceid=chrome&ie=UTF-8',
	'https://www.baidu.com/s?wd=abc%20123&rsv_spt=1&rsv_iqid=0xce0a64cb00032e6f&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=7&rsv_sug1=7&rsv_sug7=100&rsv_sug2=0&inputT=2184&rsv_sug4=2184',
	'http://localhost/test/ok.html?a=b=c=&z======1&x=1=2=3',
	'http://localhost/test/ok?a=b=c=&z======1&x=1=2=3',
	'http://localhost/test2?a[a][a]=1&a[a][b]=2',
];

let urlObjs = data.map(url => {
	return new keUrl(url);
});

urlObjs[4].setPath('../hello/world');
urlObjs[4].mergeQuery('good');
urlObjs[5].setPath('../hello/world');
urlObjs[5].mergeQuery({ a: null }); // remove a

console.log(urlObjs[4].toUrl());
console.log(urlObjs[5].toUrl());

urlObjs[6].mergeQuery({ a: { a: { a: null, b: 'bb' } } });
urlObjs[6].setQuery('a[a][c]', 'test');

urlObjs[6].hash = 'ok';

console.log(urlObjs[6].toUrl());

let clone6 = urlObjs[6].clone({protocol: 'https', hash: ''}).replaceQuery('b[b][b]=bbb&b[b][你好]=333');

console.log(urlObjs[6].toUrl(), clone6.toUrl());